program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
pelement=^element;
element=record
value:integer;
next:pelement;
end;

var
k, i, n:integer;
head:pelement;

procedure Deletethe4th(head:pelement);
var
current, current1:pelement;
tmp:integer;

begin
current:=head;
current1:=head;
tmp:=0;
while (current^.next<>nil) do
begin
current:=current^.next;
tmp:=tmp+1;
end;
if (tmp>=3) then
begin
for i:=1 to 4 do
begin
current1:=current1^.next;
writeln(head^.next^.next^.next.value);
dispose(head^.next^.next^.next);
head^.next^.next^.next:=current1;
end;
end;
end;

procedure Add(var head:pelement; num:integer);
var
a:pelement;
begin
a:=head;
new(head);
head^.next:=a;
head^.value:=num;
end;

begin
readln(n);
head:=nil;
for i:=1 to n do
begin
readln(k);
Add(head, k);
end;
for i:=1 to n do
begin
Deletethe4th(head);
end;
readln;
readln;
end.
